package com.itheima.itheima.controller;

import com.itheima.service.OrderSettingService;
import com.itheima.support.Result;
import com.itheima.util.POIUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/ordersetting")
public class OrderSettingController {

    @Reference
    private OrderSettingService orderSettingService;

    //上传表格
    @RequestMapping("/import")
    public void update(@RequestParam("excelfile") MultipartFile multipartFile) throws IOException {
        List<String[]> data = POIUtils.readExcel(multipartFile.getInputStream(), multipartFile.getOriginalFilename());
        orderSettingService.importData(data);
    }

    @RequestMapping("/findSettingData/{year}/{month}")
    public Result findsettingdata(@PathVariable("year") int year, @PathVariable("month") int month) {
        System.out.println("裕兴");
        return orderSettingService.selectByYearMonth(year,month);
        //(res)=>{
        //        if(res.data.flag){
        //          this.settingData = res.data.data
        //          this.$message.success(res.data.message)
        //        }else{
        //          this.$message.error(res.data.message)
        //        }
        //    }
    }

    @RequestMapping("updatemax/{day}/{num}")
    public boolean updatemax(@PathVariable("day")String data,@PathVariable("num")Integer num ){
       orderSettingService.updatemax(data,num);
        return true;
    }
}
